package org.jsola.hr.helper;

import org.jsola.hr.dto.EmpModifyCompanyAddDTO;
import org.jsola.hr.dto.EmpModifyCompanyUpdateDTO;
import org.jsola.hr.entity.EmpModifyCompanyDO;
import org.jsola.hr.query.EmpModifyCompanyQuery;
import org.jsola.hr.service.IEmpModifyCompanyService;
import org.jsola.hr.vo.EmpModifyCompanyVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 员工更换用工单位
 *
 * @author zhr
 */
@Component
public class EmpModifyCompanyTestHelper extends BaseTestHelper {
    
    @Autowired
    private IEmpModifyCompanyService empModifyCompanyService;

    /**
     * 生成add测试数据
     * @return EmpModifyCompanyAddDTO
     */
    public EmpModifyCompanyAddDTO getEmpModifyCompanyAddDTO(){
        EmpModifyCompanyAddDTO empModifyCompanyAddDTO = new EmpModifyCompanyAddDTO();
        empModifyCompanyAddDTO.setEmpId(getRandomValue("varchar",32));
        empModifyCompanyAddDTO.setUserId(getRandomValue("varchar",32));
        empModifyCompanyAddDTO.setOldCompanyId(getRandomValue("varchar",32));
        empModifyCompanyAddDTO.setNewCompanyId(getRandomValue("varchar",32));
        return empModifyCompanyAddDTO;
    }


    /**
     * 生成update测试数据
     * @return EmpModifyCompanyUpdateDTO
     */
    public EmpModifyCompanyUpdateDTO getEmpModifyCompanyUpdateDTO(EmpModifyCompanyVO empModifyCompanyVO){
        return empModifyCompanyService.selectDOById(empModifyCompanyVO.getId(), SITE_ID).to(EmpModifyCompanyUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return EmpModifyCompanyQuery
     */
    public EmpModifyCompanyQuery getEmpModifyCompanyQuery() {
        EmpModifyCompanyQuery empModifyCompanyQuery = new EmpModifyCompanyQuery();
        List<EmpModifyCompanyDO> empModifyCompanyDOList = empModifyCompanyService.list(new EmpModifyCompanyDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(empModifyCompanyDOList)) {
            EmpModifyCompanyDO empModifyCompanyDO = empModifyCompanyDOList.get(0);
            empModifyCompanyQuery = empModifyCompanyDO.to(EmpModifyCompanyQuery.class);
        }
        return empModifyCompanyQuery;
    }

    /**
     * 保存示例
     * @return EmpModifyCompanyVO
     */
    public EmpModifyCompanyVO saveEmpModifyCompanyExample(){
        EmpModifyCompanyAddDTO addDTO = this.getEmpModifyCompanyAddDTO();
        EmpModifyCompanyVO empModifyCompanyVO = empModifyCompanyService.save(addDTO,buildTokenUser());
        return empModifyCompanyVO;
    }


}

